<style>

</style>



<div class="layui-tab layui-tab-brief" lay-filter="user">
    <ul class="layui-tab-title" id="LAY_mine">
        <li class="layui-this" lay-id="info">网站名片</li>
        <li lay-id="avatar">主站设置</li>
        <li lay-id="email">邮箱配置</li>
        <li lay-id="pass">注册设置</li>
        <!-- <li lay-id="bind">标签设置</li> -->
        <li lay-id="bind">SEO和统计设置</li>
        <!-- <li lay-id="bind">友情链接</li> -->
    </ul>
    <div class="layui-tab-content" style="padding: 20px 0;">

        <!-- 网站名片 -->
        <div class="layui-form layui-form-pane layui-tab-item layui-show">
            <form class="layui-form" lay-filter="form-user-card">
                <div class="layui-form-item">
                    <div class="avatar-add">
                        <p>建议尺寸168*168，支持jpg、png、gif，最大不能超过2M</p>
                        <button id="upload_head_image" type="button" class="layui-btn upload-img">
                            <i class="layui-icon">&#xe67c;</i>上传Logo
                        </button>
                        <img id="site_logo_img" src="">
                        <span class="loading"></span>
                    </div>
                </div>
                <input type="text" class="layui-hide" id="site_logo" name="site_logo">

                <div class="layui-form-item">
                    <label class="layui-form-label">ico图标</label>
                    <div class="layui-input-inline">
                        <img src="" id="site_ico_img" style="width: 32px;height: 32px;margin-left: 20px;margin-top: 3px;border: 1px solid #f2f2f2;" alt="">
                        <input type="text" id="site_ico" class="layui-hide" name="site_ico"
                            value="" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><a class="layui-btn layui-btn-xs" id="upload_ico_btn">上传</a></div>
                    <div class="layui-form-mid layui-word-aux">建议尺寸16*16</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="site_title" required lay-verify="required"
                            autocomplete="off" value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">网站简介</label>
                    <div class="layui-input-block">
                        <textarea placeholder="网站标题下的简介，建议保持20字以内" name="site_autograph" autocomplete="off"
                            class="layui-textarea" style="height: 80px;"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="submit-user-card">确认修改</button>
                    </div>
                </div>
            </form>
        </div>

        <!-- 页面设置 -->
        <div class="layui-form layui-form-pane layui-tab-item">
           <form class="layui-form" lay-filter="form-site">
            <div class="layui-form-item">
                <label  class="layui-form-label">主站域名</label>
                <div class="layui-input-inline">
                    <input type="text" name="site_domain" id="site_domain" placeholder="例：http:www.xxx.com" autocomplete="off" value=""
                        class="layui-input">
                    <div class="layui-form-mid layui-word-aux"><button class="layui-btn layui-btn-xs" id="use_current_domain">使用当前网站域名</button><p>应用于外部跳转到主站，例如邮件内等</p></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">关于链接</label>
                <div class="layui-input-inline">
                    <input type="text" name="site_about_url" placeholder="点击“关于”跳转的地址" autocomplete="off" value=""
                        class="layui-input">
                    <div class="layui-form-mid layui-word-aux">
                        <!-- <div class="layui-btn layui-btn-xs" id="select_article_btn">选择文章</div> -->
                        <!-- <p>可以选择公开的文章或者直接添加链接，不填写将不显示关于</p> -->
                        <p>可以设置外部链接，留空隐藏关于项</p>
                    </div>
                </div>
                
            </div>
      
            <!-- <div class="layui-form-item">
                <label class="layui-form-label">背景图</label>
                <div class="layui-input-inline">
                    <input type="text" name="site_background_image" placeholder="点击“关于”跳转的地址" autocomplete="off" value=""
                        class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><button class="layui-btn layui-btn-xs">选择文章</button> 作为“关于”页面跳转的地址 </div>
            </div> -->
            <div class="layui-form-item">
                <label title="ICP备案信息" class="layui-form-label">ICP备案号</label>
                <div class="layui-input-inline">
                    <input type="text" name="site_icp"  autocomplete="off" value=""
                        class="layui-input" placeholder="例：京ICP备XXXX号">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submit-site">保存</button>
                </div>
            </div>
           </form>
        </div>

        <!-- 邮箱设置 -->
        <div class="layui-form layui-form-pane layui-tab-item">
            <form class="layui-form" lay-filter="form-email">
                <blockquote class="layui-elem-quote">此邮箱是用作用户找回密码、注册等操作下发的系统级别邮箱。</blockquote>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">发信人邮箱</label>
                    <div class="layui-input-inline">
                        <input type="text" name="email_address" required lay-verify="required" required lay-verify="email" placeholder="请输入发信人邮箱" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
            
                <div class="layui-form-item">
                    <label class="layui-form-label">服务器地址</label>
                    <div class="layui-input-inline">
                        <input type="text" name="email_host" required lay-verify="required" placeholder="请输入SMTP 服务器地址" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
            
                <div class="layui-form-item">
                    <label class="layui-form-label">服务器端口</label>
                    <div class="layui-input-inline">
                        <input type="number" name="email_port" required lay-verify="required" placeholder="请输入SMTP 端口" autocomplete="off"
                            class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">常用:25,465,587</div>
                </div>
            
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱密码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="email_password" required lay-verify="required" placeholder="请输入发信人密码或授权码"
                            autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">部分邮箱是授权码</div>
                </div>
            
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label">加密方式</label>
                    <div class="layui-input-inline">
                        <select name="email_secure" lay-verify="required">
                            <option value="tls">TLS</option>
                            <option value="ssl">SSL(加密连接)</option>
                        </select>
                    </div>
                </div> -->
            
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-xs" lay-submit lay-filter="sendTestMail">发送测试邮件</button>
                    </div>
                </div>
            
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="submit-email">保存</button>
                    </div>
                </div>
            </form>
        </div>

        <!-- 注册设置 -->
        <div class="layui-form layui-tab-item">
            <form class="layui-form" lay-filter="form-register">
                <div class="layui-form-item">
                    <label class="layui-form-label">注册方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="register_method" value="1" title="开放">
                        <!-- <input type="radio" name="register_method" value="2" title="邀请码注册" > -->
                        <input type="radio" name="register_method" value="3" title="关闭" checked>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱后缀</label>
                    <div class="layui-input-inline">
                        <input type="text" name="register_email_suffix" placeholder="(可空)例如：@abc.com" autocomplete="off" value=""
                            class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><p>限制新注册邮箱的后缀，一般用于企业邮箱。后台添加用户不受影响</p> </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="submit-register">保存</button>
                    </div>
                </div>
            </form>
        </div>

        <!-- 标签设置 -->
        <!-- <div class="layui-form layui-form-pane layui-tab-item">
            <form  class="layui-form" lay-filter="form-tag">
                <div class="layui-form-item">
                    <label class="layui-form-label">创建标签</label>
                    <div class="layui-input-block">
                        <input type="radio" name="tag_user_create" value="1" title="是">
                        <input type="radio" name="tag_user_create" value="2" title="否" checked>
                    </div>
                    <div class="layui-form-mid layui-word-aux">是否允许用户创建标签 </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="submit-tag">保存</button>
                    </div>
                </div>
            </form>
        </div> -->

        <!-- SEO设置 -->
        <div class="layui-form layui-form-pane layui-tab-item">
            <form class="layui-form" lay-filter="form-seo">
               
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-block">
                        <textarea placeholder="网站的关键字,可使用英文逗号分隔" name="seo_site_keywords" autocomplete="off" class="layui-textarea"
                            style="height: 80px;"></textarea>
                    </div>
                </div>
             
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">网站描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="网站的描述" name="seo_site_description" autocomplete="off" class="layui-textarea"
                            style="height: 80px;"></textarea>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">统计代码</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请直接在统计网站复制粘贴到这里" name="seo_tongji" autocomplete="off" class="layui-textarea"
                            style="height: 80px;"></textarea>
                    </div>
                </div>
                <!-- <div class="layui-form-item">
                    <label class="layui-form-label">百度推送</label>
                    <div class="layui-input-inline">
                        <input type="text" name="seo_baidu_tuisong" lay-verify=""
                            placeholder="百度推送的id" autocomplete="off" class="layui-input">
                    </div>
                </div> -->

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="submit-seo">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>


</div>

<script>
    //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element', 'form', 'table', 'jquery',"layer","upload"], function () {
        var element = layui.element, table = layui.table, form = layui.form,layer=layui.layer, upload=layui.upload,$=layui.$;
        form.render()
        // 读取
        app.base.ajaxGet("/api/global/get/globalInfo",function(res){
            // console.log(res)
            $("#site_logo_img").attr("src", "/" + res.site_logo);
            $("#site_ico_img").attr("src", "/" + res.site_ico);
            form.val("form-user-card", res)
            form.val("form-site", res)
            form.val("form-tag", res)
            form.val("form-seo", res)
            form.val("form-email", res)
            form.val("form-register", res)
        })
        // 保存
        form.on('submit(submit-user-card)', function (data) {
            data.field.part="site"
            app.base.ajaxPost("/api/admin/setting/setGlobalSetting", data.field,function(res){
                layer.msg("保存成功")
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(submit-site)', function (data) {
            data.field.part = "site"
            app.base.ajaxPost("/api/admin/setting/setGlobalSetting", data.field, function (res) {
                layer.msg("保存成功")
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(submit-register)', function (data) {
            
            data.field.part = "register"
            app.base.ajaxPost("/api/admin/setting/setGlobalSetting", data.field, function (res) {
                layer.msg("保存成功")
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(submit-email)', function (data) {
            data.field.part = "email"
            app.base.ajaxPost("/api/admin/setting/setGlobalSetting", data.field, function (res) {
                layer.msg("保存成功")
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(submit-tag)', function (data) {
            data.field.part = "tag"
            app.base.ajaxPost("/api/admin/setting/setGlobalSetting", data.field, function (res) {
                layer.msg("保存成功")
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(submit-seo)', function (data) {
            data.field.part = "seo"
            app.base.ajaxPost("/api/admin/setting/setGlobalSetting", data.field, function (res) {
                layer.msg("保存成功")
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        // 发送测试邮件
        form.on('submit(sendTestMail)', function (data) {
            data.field;
            
            layer.prompt({ title: '请输入要接收测试邮件的邮箱账号', formType: 0 }, function (text, index) {
                var d = {
                    "test_mail": text,
                    "address": data.field.email_address,
                    "pass": data.field.email_password,
                    "host": data.field.email_host,
                    "port": data.field.email_port
                }
                app.base.ajaxPost("/api/admin/setting/sendTestMail",d, function () {
                    layer.msg('测试邮箱已发送，请去邮箱查收');
                }, function (msg) {
                    layer.msg(msg);
                })
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        // 使用当前域名
        $("#use_current_domain").click(function(){
            var domian= location.protocol + "//" + location.hostname + (location.port == "" ? "" : (":" + location.port));
            $("#site_domain").val(domian)
            layer.alert("获取到的域名为："+ domian+"。请人为判断域名的准确性。<br>否则可能导致邮件中链接无法打开")
            return false
        })

        // 选择文章
        // $("#select_article_btn").click(function(){
        //     app.runTpl("searchArticle")
        // })


        // 上传logo
        upload.render({
            elem: '#upload_head_image'
            , url: '/api/admin/setting/uploadLogo' 
            , field:"image"
            , headers: { "token": app.base.getUserInfo().token }
            , done: function (res) {
                if (res.code != 0) {
                    return layer.msg('上传失败');
                }
    
                $('#site_logo').val(res.data); 
                $("#site_logo_img").attr("src","/"+res.data);
            }
        });

        // 上传ICO
        upload.render({
            elem: '#upload_ico_btn' 
            , field: "image"
            , url: '/api/admin/setting/uploadIco' 
            , exts:"ico"
            , acceptMime:"image/x-icon"
            , headers: { "token": app.base.getUserInfo().token }
            , done: function (res) {
                //上传完毕回调
                $('#site_ico').val(res.data);
                $("#site_ico_img").attr("src", "/" + res.data);
            }
        });
        
    });
</script>